﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SecurePlayer
{
    public partial class Chat : Form
    {
        private VlcPlayer _frmMain;
        public string SourceID = string.Empty;
        private bool reset = false;

        public Chat(VlcPlayer formMain)
        {
            _frmMain = formMain;
            InitializeComponent();
        }

        public void NewMessage(string MessageText)
        {
            string current = textBox1.Text;
            current = current + Environment.NewLine + "Remote: " + MessageText;
            textBox1.Text = current;
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        { 
            if (e.KeyChar == (char)Keys.Enter)
            {
                string current = textBox1.Text;
                current = current + Environment.NewLine + "Ich: " + textBox2.Text;
                textBox1.Text = current;
                _frmMain.ChatSendMessage(SourceID, textBox2.Text);
                reset = true;
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            textBox1.SelectionStart = textBox1.Text.Length;
            textBox1.ScrollToCaret();
            textBox1.Refresh();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            if (reset)
            {
                textBox2.Text = "";
                reset = false;
            }
        }   
    }
}
